package com.quktzhuanka.app.fragments;


import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.ali.auth.third.core.model.Session;
import com.alibaba.baichuan.trade.biz.login.AlibcLogin;
import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback;
import com.bumptech.glide.Glide;
import com.google.gson.reflect.TypeToken;
import com.quktzhuanka.app.CaiNiaoApplication;
import com.quktzhuanka.app.MainActivity;
import com.quktzhuanka.app.R;
import com.quktzhuanka.app.activity.DailyBonusActivity;
import com.quktzhuanka.app.activity.DiTuiImgActivity;
import com.quktzhuanka.app.activity.FeedBackActivity;
import com.quktzhuanka.app.activity.InComeActivity;
import com.quktzhuanka.app.activity.KfActivity;
import com.quktzhuanka.app.activity.MyMarketActivity;
import com.quktzhuanka.app.activity.NewClassActivity;
import com.quktzhuanka.app.activity.SetActivity;
import com.quktzhuanka.app.activity.SysMessageActivity;
import com.quktzhuanka.app.activity.TeamIncomeNewActivity;
import com.quktzhuanka.app.activity.VIPActivity;
import com.quktzhuanka.app.activity.WebViewActivity3;
import com.quktzhuanka.app.activity.WebViewActivityz;
import com.quktzhuanka.app.base.BaseLazyFragment;
import com.quktzhuanka.app.bean.GroupListBean;
import com.quktzhuanka.app.bean.UserBalanceRecordBean;
import com.quktzhuanka.app.bean.UserBean;
import com.quktzhuanka.app.bean.UserInfoBean;
import com.quktzhuanka.app.common.ACache;
import com.quktzhuanka.app.common.CommonUtils;
import com.quktzhuanka.app.common.LogUtils;
import com.quktzhuanka.app.common.SPUtils;
import com.quktzhuanka.app.common.T;
import com.quktzhuanka.app.config.Constants;
import com.quktzhuanka.app.https.HttpUtils;
import com.quktzhuanka.app.https.onOKJsonHttpResponseHandler;
import com.quktzhuanka.app.login.WelActivity;
import com.quktzhuanka.app.my.CollectionActivity;
import com.quktzhuanka.app.my.MyInformationActivity;
import com.quktzhuanka.app.my.MyMessageActivity;
import com.quktzhuanka.app.my.MyOrderActivity;
import com.quktzhuanka.app.my.MyShareUrlActivity;
import com.quktzhuanka.app.my.PutForwardActivity;
import com.quktzhuanka.app.utils.BroadcastContants;
import com.quktzhuanka.app.utils.BroadcastManager;
import com.quktzhuanka.app.utils.FixedHeadScrollView;
import com.quktzhuanka.app.utils.MyScrollView;
import com.quktzhuanka.app.widget.CircleImageView;
import com.google.gson.Gson;
import com.loopj.android.http.RequestParams;
import com.loopj.android.http.TextHttpResponseHandler;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cz.msebera.android.httpclient.Header;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
/**
 * 我的
 * Created by wim
 */

public class MyFragment extends BaseLazyFragment implements FixedHeadScrollView.FixedHeadScrollViewListener {
    public static final String TAG = "MyFragment";
    @BindView(R.id.civ_head)
    CircleImageView civ_head;
    @BindView(R.id.txt_name)
    TextView txtName;
    @BindView(R.id.tv_username)
    TextView tv_username;
    @BindView(R.id.txt_market_income)
    TextView txtMarketIncome;
//    @BindView(R.id.view_one)
//    View viewOne;
//    @BindView(R.id.img_one)
//    ImageView imgOne;
//    @BindView(R.id.view_two)
//    View viewTwo;
//    @BindView(R.id.img_two)
//    ImageView imgTwo;
//    @BindView(R.id.view_three)
//    View viewThree;
//    @BindView(R.id.img_three)
//    ImageView imgThree;
//    @BindView(R.id.txt_four)
//    TextView txtfour;
//    @BindView(R.id.txt_one)
//    TextView txtOne;
//    @BindView(R.id.txt_two)
//    TextView txtTwo;
//    @BindView(R.id.txt_three)
//    TextView txtThree;

    // start   田哥哥  2020年6月19日14:38:39
    @BindView(R.id.txt_eleven)
    TextView txtEleven;
    @BindView(R.id.txt_twelve)
    TextView txtTwelve;
    @BindView(R.id.txt_thirteen)
    TextView txtThirteen;
    @BindView(R.id.txt_fourteen)
    TextView txtFourteen;
    // end



    private View view;
    public static MyFragment fragment;
    private Bundle bundle;
    @BindView(R.id.fix_scol)
    MyScrollView myScrollView;
//    @BindView(R.id.txt_grade)
//    TextView txtGrade;
//    @BindView(R.id.total_exp)
//    TextView totalExp;
    @BindView(R.id.tx_yue)
    TextView txYue;
    private ACache mAcache;
    String token = "";
    private UserInfoBean userBean;
    @BindView(R.id.ll_top)
    RelativeLayout llTop;
    @BindView(R.id.ll_info)
    LinearLayout llINfo;
    @BindView(R.id.txt_set2)
    ImageView set2;
    @BindView(R.id.txt_code)
    TextView txtCode;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;
    private UserBalanceRecordBean recordBean;
    // 标志位，标志已经初始化完成。
    private boolean isPrepared;
    Intent intent;
    private AlibcLogin alibcLogin;

    public static MyFragment getInstance() {
        if (fragment == null) {
            fragment = new MyFragment();
        }
        return fragment;
    }

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_my, container, false);
        ButterKnife.bind(this, view);
        llTop.measure(0, 0);
        llTop.getBackground().mutate().setAlpha(0);
        init();
        addListener();
        getUserMsg();
        getVipData();
        return view;
    }

    private void init() {
        alibcLogin = AlibcLogin.getInstance();
    }


    private void addListener() {
        refreshLayout.setEnableLoadMore(false);
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                getUserMsg();
                getVipData();
            }
        });
        myScrollView.setScrolListener(new MyScrollView.OnScrollListener() {
            @Override
            public void onScroll(int scrollY) {
                if (scrollY < 0)
                    return;
                if (scrollY > llTop.getMeasuredHeight()) {
                    llTop.getBackground().mutate().setAlpha(255);
                } else {
                    llINfo.setScaleX(1 - scrollY * 1.0f / llTop.getMeasuredHeight());
                    llINfo.setScaleY(1 - scrollY * 1.0f / llTop.getMeasuredHeight());
                    txtName.setScaleX(scrollY * 1.0f / llTop.getMeasuredHeight());
                    txtName.setScaleY(scrollY * 1.0f / llTop.getMeasuredHeight());
                    set2.setScaleX(scrollY * 1.0f / llTop.getMeasuredHeight());
                    set2.setScaleY(scrollY * 1.0f / llTop.getMeasuredHeight());
                    llTop.getBackground().mutate().setAlpha((int) (scrollY * 1.00 * 255 / llTop.getMeasuredHeight()));
                }
            }
        });
    }

    @Override
    protected void lazyload() {
    }

    /**
     * @属性:接收登录的成功的消息
     * @开发者:田哥哥
     * @时间:2018/7/21 14:55
     */
    @Override
    protected void ReceiverIsLoginMessage() {
        super.ReceiverIsLoginMessage();
        //发送消息选择我的页

    }

    /**
     * @属性:接收广播队列
     * @开发者:田哥哥
     * @时间:2018/7/29 16:16
     */
    @Override
    protected void ReceiverBroadCastMessage(String status, String result, Serializable serializable, Intent intent) {
        super.ReceiverBroadCastMessage(status, result, serializable, intent);
        //接收修改用户信息，那么刷新当前用户信息
        if (BroadcastContants.sendUserMessage.equals(status)) {
            getUserMsg();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //销毁广播
        BroadcastManager.getInstance(getActivity()).destroy(BroadcastContants.sendUserMessage);
    }

    @OnClick({R.id.txt_mes,R.id.tx_button, R.id.txt_vip, R.id.txt_hz, R.id.btn_copy, R.id.civ_head, R.id.user_details_1,R.id.user_details_2, R.id.txt_collect, R.id.txt_market_income, R.id.ll_vip, R.id.txt_market, R.id.txt_tj, R.id.txt_sy, R.id.txt_dd, R.id.txt_kf,  R.id.txt_set, R.id.txt_set2,R.id.txt_renwu,R.id.txt_ditui,R.id.txt_zhuanka,R.id.txt_xuanshang,R.id.txt_real})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.txt_mes:
                openActivity(SysMessageActivity.class);
                break;
            case R.id.btn_copy:
                ClipboardManager cmb = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                cmb.setText(txtCode.getText().toString().trim());
                T.showShort(context, "复制成功，快去邀请好友吧");
                break;
            case R.id.civ_head:
            case R.id.user_details_1:
            case R.id.user_details_2:
                openActivity(MyInformationActivity.class);
                break;
            case R.id.txt_market_income:
                openActivity(TeamIncomeNewActivity.class);
                break;
            case R.id.txt_collect:
                openActivity(CollectionActivity.class);
                break;
            case R.id.ll_vip:
                openActivity(NewClassActivity.class);
//                EventBus.getDefault().post(new MessageEvent("huiyuan"));
                break;
            case R.id.txt_sy:
                openActivity(InComeActivity.class);
                break;
            case R.id.txt_dd:
                whetherBindingTaobao();
                break;
//            case R.id.txt_gg:
//                openActivity(MyMessageActivity.class);
//                break;
            case R.id.txt_kf:
                openActivity(KfActivity.class);
//                CommonUtils.getContactCustomerService(getActivity());
                break;
//            case R.id.txt_fk:
//                Intent intent = new Intent(context, FeedBackActivity.class);
//                intent.putExtra("type", 1);
//                startActivity(intent);
//                break;
            case R.id.txt_set2:
            case R.id.txt_set:
                openActivity(SetActivity.class);
                break;
            case R.id.txt_tj:
                openActivity(MyShareUrlActivity.class);
                break;
            case R.id.txt_market:
                openActivity(MyMarketActivity.class);
                break;
            case R.id.txt_vip:
                openActivity(VIPActivity.class);
                break;
//              switchFragment(new VIPFragment()).commit();
//              NewsActivity.actionStart(context, "27", "关于我们");
            case R.id.txt_hz:
                intent = new Intent(context, FeedBackActivity.class);
                intent.putExtra("type", 2);
                startActivity(intent);
                break;
            case R.id.tx_button:   // 提现
                Bundle b = new Bundle();
                b.putString("balance", userBean.user_msg.balance);
                openActivity(PutForwardActivity.class, b);
                break;
            case R.id.txt_renwu:   // 任务中心（签到）
//                intent = new Intent(context, WebViewActivity3.class);
//                intent.putExtra("title", "测试一下");
//                intent.putExtra("url", "file:///android_asset/dist/index.html");
//                startActivity(intent);
                openActivity(DailyBonusActivity.class);
                break;

            case R.id.txt_ditui:   // 地推物料
//                intent = new Intent(context, FullScreenVideoActivity.class);
//                intent.putExtra("vertical_rit",Constants.vertical_rit);
//                startActivity(intent);
                openActivity(DiTuiImgActivity.class);
                break;
            case R.id.txt_zhuanka:   // 我的赚咖
                intent = new Intent(context, WebViewActivityz.class);
                intent.putExtra("title", "我的赚咖");
                intent.putExtra("url", Constants.GET_ZHUANKA_USER);
                startActivity(intent);
                break;
            case R.id.txt_xuanshang:   // 我的悬赏
                intent = new Intent(context, WebViewActivityz.class);
                intent.putExtra("title", "我的悬赏");
                intent.putExtra("url", Constants.APP_IP + "/wap.php/renwu/center?token=" + SPUtils.getStringData(context, "token", ""));
                startActivity(this.intent);
                break;
            case R.id.txt_real:   // 实名认证
                intent = new Intent(context, WebViewActivityz.class);
                intent.putExtra("title", "实名认证");
                intent.putExtra("url", Constants.APP_IP + "/make.php/Index/my_realname?token=" + SPUtils.getStringData(context, "token", ""));
                startActivity(this.intent);
                break;
        }
    }

    //是否绑定淘宝账号
    private void whetherBindingTaobao() {
        String url = Constants.WHETHER_BINDING_TAOBAO;
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody body = new FormBody.Builder().add("token", SPUtils.getStringData(context, "token", "")).build();
        Request request = new Request.Builder().url(url).post(body).build();
        Call call = okHttpClient.newCall(request);
        showLoadingDialog("检测绑定淘宝");
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
                closeLoadingDialog();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String result = response.body().string();
                closeLoadingDialog();
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String code = jsonObject.getString("code");
                    if ("105".equals(code)) {
                        showToast("登录信息已过期");
                        openActivity(WelActivity.class);
                        return;
                    }
                    JSONObject jsonData = jsonObject.getJSONObject("data");
                    String isBinding = jsonData.optString("is_binding");
                    if ("N".equals(isBinding)) {
                        //如果未绑定
                        alibcLogin.showLogin(new AlibcLoginCallback() {
                            @Override
                            public void onSuccess(int i, String s, String s1) {
                                if(s==null){
                                    return;
                                }
                                 Session session = AlibcLogin.getInstance().getSession();
                                 s = session.userid;
                                int length = s.length();
                                if (length > 6) {
                                    String b = s.substring(length - 6, length);
                                    String[] bArr = b.split("");
                                    String c = bArr[1] + "" + bArr[2] + "" + bArr[5] + "" + bArr[6] + "" + bArr[3] + "" + bArr[4];
                                    bindingTaobao(c);
//                                    int i=0;
                                }
                            }
                            @Override
                            public void onFailure(int code, String msg) {

                                Log.i("FanliActivity", "淘宝授权登录失败信息=" + msg);
                                MyFragment.this.getActivity().runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        Toast.makeText(MyFragment.this.getActivity(), "请您进行淘宝授权后再进行操作",
                                                Toast.LENGTH_LONG).show();
                                    }
                                });
                            }
                        });


                    } else {
                        openActivity(MyOrderActivity.class);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    //绑定淘宝账号
    private void bindingTaobao(String tb_uid) {
        String url = Constants.BINDING_TAOBAO;
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody body = new FormBody.Builder().add("token", SPUtils.getStringData(context, "token", "")).add("tb_uid", tb_uid).build();
        Request request = new Request.Builder().url(url).post(body).build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String result = response.body().string();
                try {
                    JSONObject jsonObject = new JSONObject(result);
                    String code = jsonObject.getString("code");
                    if ("0".equals(code)) {
                        MyFragment.this.getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                openActivity(MyOrderActivity.class);
                                Toast.makeText(MyFragment.this.getActivity(), "绑定淘宝账号成功",
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                    } else {
                        Toast.makeText(MyFragment.this.getActivity(), "绑定淘宝账号失败",
                                Toast.LENGTH_LONG).show();
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
    }

    /**
     * 获取用户信息
     */
    private void getUserMsg() {
        if (!CommonUtils.isNetworkAvailable()) {
            showToast(getResources().getString(R.string.error_network));
            return;
        }
        RequestParams params = new RequestParams();
//        params.put("token", token);
        HttpUtils.post(Constants.GET_USER_MSG, params, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                // 输出错误信息
                LogUtils.e(TAG, "onFailure()--" + responseString);
            }

            @Override
            public void onFinish() {
                // 隐藏进度条
                super.onFinish();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject jsonObject = new JSONObject(responseString);
                    //返回码
                    int code = jsonObject.optInt("code");
                    //返回码说明
                    String msg = jsonObject.optString("msg");
                    String data = jsonObject.optString("data");
                    if (0 == code) {
                        if (!TextUtils.isEmpty(data)) {//GSON对数字都当做double解析
                            Gson gson = new Gson();
                            userBean = gson.fromJson(data.trim(), UserInfoBean.class);
                            CaiNiaoApplication.setUserInfoBean(userBean);
                        }
                        if (null != userBean) {
                            CaiNiaoApplication.setUserBean(new UserBean(userBean.user_detail.user_id, userBean.user_msg.group_id, token, userBean.user_detail.avatar, userBean.user_detail.nickname, userBean.user_msg.is_forever));
                            SPUtils.saveStringData(context, "phone", userBean.user_msg.phone);
                            SPUtils.saveIntData(context, "rate", Integer.parseInt(userBean.user_msg.commission_rate));
                            if (null != userBean.user_detail) {
                                if (!TextUtils.isEmpty(userBean.user_detail.nickname)) {
                                    tv_username.setText(userBean.user_detail.nickname);
                                    txtName.setText(userBean.user_detail.nickname);
                                } else {
                                    tv_username.setText(userBean.user_msg.phone);
                                    txtName.setText(userBean.user_msg.phone);
                                }
                                txtCode.setText(CaiNiaoApplication.getUserInfoBean().user_msg.auth_code);
                                Glide.with(context).load(userBean.user_detail.avatar).dontAnimate().placeholder(R.mipmap.icon_defult_boy).error(R.mipmap.icon_defult_boy).into(civ_head);
                                mAcache = ACache.get(getActivity());
                                if (null != userBean) {
                                    if (null != userBean.user_detail && null != userBean.user_detail.avatar) {
                                        mAcache.put("avatar", userBean.user_detail.avatar);
                                    }
                                    if (null != userBean.user_msg && null != userBean.user_msg.group_id) {
                                        mAcache.put("group_id", userBean.user_msg.group_id);
                                        if ("3".equals(userBean.user_msg.group_id) || "4".equals(userBean.user_msg.group_id)){
                                            txtMarketIncome.setVisibility(View.VISIBLE);
                                        }else{
                                            txtMarketIncome.setVisibility(View.GONE);
                                        }
//                                        if ("3".equals(userBean.user_msg.group_id)) {
//                                            txtMarketIncome.setVisibility(View.VISIBLE);
//                                            viewOne.setBackgroundColor(context.getResources().getColor(R.color.gold));
//                                            viewTwo.setBackgroundColor(context.getResources().getColor(R.color.gold));
//                                            viewThree.setBackgroundColor(context.getResources().getColor(R.color.blue_1));
//                                            imgOne.setImageResource(R.drawable.shape_dot);
//                                            imgTwo.setImageResource(R.drawable.ic_dot);
//                                            imgThree.setImageResource(R.drawable.shape_dot_gray);
//                                            txtOne.setTextColor(context.getResources().getColor(R.color.black));
//                                            txtTwo.setTextColor(context.getResources().getColor(R.color.black));
//                                            txtThree.setTextColor(context.getResources().getColor(R.color.gray));
//                                        } else if ("4".equals(userBean.user_msg.group_id)) {
//                                            txtMarketIncome.setVisibility(View.VISIBLE);
//                                            viewOne.setBackgroundColor(context.getResources().getColor(R.color.gold));
//                                            viewTwo.setBackgroundColor(context.getResources().getColor(R.color.gold));
//                                            viewThree.setBackgroundColor(context.getResources().getColor(R.color.gold));
//                                            imgOne.setImageResource(R.drawable.shape_dot);
//                                            imgTwo.setImageResource(R.drawable.shape_dot);
//                                            imgThree.setImageResource(R.drawable.ic_dot);
//                                            txtOne.setTextColor(context.getResources().getColor(R.color.black));
//                                            txtTwo.setTextColor(context.getResources().getColor(R.color.black));
//                                            txtThree.setTextColor(context.getResources().getColor(R.color.black));
//                                        } else if ("2".equals(userBean.user_msg.group_id)) {
//                                            tv_isvip.setText("奋斗熊");
//                                            txtMarketIncome.setVisibility(View.GONE);
//                                            viewOne.setBackgroundColor(context.getResources().getColor(R.color.gold));
//                                            viewTwo.setBackgroundColor(context.getResources().getColor(R.color.blue_1));
//                                            viewThree.setBackgroundColor(context.getResources().getColor(R.color.blue_1));
//                                            imgOne.setImageResource(R.drawable.ic_dot);
//                                            imgTwo.setImageResource(R.drawable.shape_dot_gray);
//                                            imgThree.setImageResource(R.drawable.shape_dot_gray);
//                                            txtOne.setTextColor(context.getResources().getColor(R.color.black));
//                                            txtTwo.setTextColor(context.getResources().getColor(R.color.gray));
//                                            txtThree.setTextColor(context.getResources().getColor(R.color.gray));
//                                        } else {
//                                            tv_isvip.setText("成长熊");
//                                            txtMarketIncome.setVisibility(View.GONE);
//                                            viewOne.setBackgroundColor(context.getResources().getColor(R.color.blue_1));
//                                            viewTwo.setBackgroundColor(context.getResources().getColor(R.color.blue_1));
//                                            viewThree.setBackgroundColor(context.getResources().getColor(R.color.blue_1));
//                                            imgOne.setImageResource(R.drawable.shape_dot_gray);
//                                            imgTwo.setImageResource(R.drawable.shape_dot_gray);
//                                            imgThree.setImageResource(R.drawable.shape_dot_gray);
//                                            txtOne.setTextColor(context.getResources().getColor(R.color.gray));
//                                            txtTwo.setTextColor(context.getResources().getColor(R.color.gray));
//                                            txtThree.setTextColor(context.getResources().getColor(R.color.gray));
//                                        }
                                    }
                                }
                                getUserMoney();
                            }
                        }
                    } else {
                        showToast(msg);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onStart() {
                super.onStart();
            }
        });
    }
    private void getUserMoney() {
        RequestParams requestParams = new RequestParams();
        HttpUtils.post(Constants.INCOME_USER_TATICS, requestParams, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            }

            @Override
            public void onStart() {
                super.onStart();
                showLoadingDialog();
            }

            @Override
            public void onFinish() {
                super.onFinish();
                closeLoadingDialog();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject temp2 = new JSONObject(responseString);
                    if(temp2.getInt("code")==0){
                        JSONObject temp = new JSONObject(responseString).getJSONObject("data");
                        txtEleven.setText(String.format(getResources().getString(R.string.test_text), temp.getString("today_amount"), "今日预估"));
                        txtTwelve.setText(String.format(getResources().getString(R.string.test_text), temp.getString("yesterday_amount"), "昨日预估"));
                        txtThirteen.setText(String.format(getResources().getString(R.string.test_text), temp.getString("amount_current"), "本月预估"));
                        txtFourteen.setText(String.format(getResources().getString(R.string.test_text), temp.getString("amount_last_finish"), "上月预估"));
                    }else{
                        showToast(temp2.getString("msg"));
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }



//    private void getGroupList() {
//        RequestParams requestParams = new RequestParams();
//        HttpUtils.post(Constants.GROUP_LIST, requestParams, new onOKJsonHttpResponseHandler<GroupListBean>(new TypeToken<com.quktzhuanka.app.bean.Response<GroupListBean>>() {
//        }) {
//            @Override
//            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
//
//            }
//
//            @Override
//            public void onSuccess(int statusCode, com.quktzhuanka.app.bean.Response<GroupListBean> datas) {
//                if (datas.isSuccess()) {
//                    List<GroupListBean.Item> items=datas.getData().list;
//                    for (int i=0;i<items.size();i++){
//                        switch (i){
//                            case 0:
//                                txtfour.setText(items.get(i).title);
//                                break;
//                            case 1:
//                                txtOne.setText(items.get(i).title);
//                                break;
//                            case 2:
//                                txtTwo.setText(items.get(i).title);
//                                break;
//                            case 3:
//                                txtThree.setText(items.get(i).title);
//                                break;
//                        }
//                    }
//                } else {
//                    showToast(datas.getMsg());
//                }
//            }
//        });
//    }
    private void getVipData() {
        RequestParams params = new RequestParams();
        HttpUtils.post(Constants.GET_VIP_DATA, params, new TextHttpResponseHandler() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                // 输出错误信息
            }

            @Override
            public void onFinish() {
                // 隐藏进度条
                super.onFinish();
                refreshLayout.finishRefresh();
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, String responseString) {
                try {
                    JSONObject jsonObject = new JSONObject(responseString);
                    //返回码
                    int code = jsonObject.optInt("code");
                    //返回码说明
                    String msg = jsonObject.optString("msg");
                    if (0 == code) {
//                        txtGrade.setText(jsonObject.getJSONObject("data").getString("exp"));
                        txYue.setText(jsonObject.getJSONObject("data").getString("balance"));
                    } else {
                        showToast(msg);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onStart() {
                super.onStart();
            }
        });
    }

    @Override
    public void onResume() {
        super.onResume();
        token = SPUtils.getStringData(context, "token", "");
        if("1".equals(SPUtils.getStringData(context,"is","1"))){
            refreshLayout.autoRefresh();
            SPUtils.saveStringData(context,"is","0");
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
    }

    @Override
    public void sendDistanceY(int distance) {

    }
}
